<?php

include_once 'DataProvider.php';
include_once 'Entity.php';

class Cart extends Entity {

    public $dataProvider;

    public function __construct() {
        $this->dataProvider = new DataProvider();
    }

    public function capNhatCart($user,$data){
        $user = mysql_real_escape_string($user);
        $data = mysql_real_escape_string($data);
        if($this->ktUserTrongCart($user)){
            $sql = "update cart set cart.`data` = '$data' where cart.`user` = '$user'";
        }else{
            $sql = "insert into `cart` (user,data) values ('$user','$data')";
        }
        return $this->dataProvider->ExecuteQuery($sql);       
    }
    
    private function ktUserTrongCart($user){
        $sql = "select cart.`user` from cart where cart.`user` = '$user'";
        $row = $this->dataProvider->GetOneRow($sql);       
        return count($row)>0;
    }
}
?>
